package com.wing.product.service;

import cn.hutool.core.util.ObjectUtil;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.wing.common.utils.JsonResult;
import com.wing.product.dao.WarehouseProductProducerDao;
import com.wing.product.model.entity.WarehouseProductProducer;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

@Service
public class WarehouseProductProducerServiceImpl extends ServiceImpl<WarehouseProductProducerDao, WarehouseProductProducer> implements WarehouseProductProducerService{

    @Override
    public Page<WarehouseProductProducer> pageList4app(Page page, Map<String, Object> params) {
        List<WarehouseProductProducer> list = baseMapper.list4app(page, params);
        page.setRecords(list);
        return page;
    }

    @Override
    public JsonResult saveWarehouseProductProducer(WarehouseProductProducer warehouseProductProducer) {
        JsonResult jsonResult = new JsonResult<>();
        if (ObjectUtil.isNotEmpty(warehouseProductProducer)){
            baseMapper.insert(warehouseProductProducer);
            return jsonResult.success("添加成功");
        }else {
            return jsonResult.fail("添加失败");
        }
    }

    @Override
    public JsonResult update(WarehouseProductProducer warehouseProductProducer) {
        JsonResult jsonResult = new JsonResult<>();
        if (ObjectUtil.isNotEmpty(warehouseProductProducer)){
            baseMapper.updateById(warehouseProductProducer);
            return jsonResult.success("修改成功");
        }else {
            return jsonResult.fail("修改失败");
        }
    }


    @Override
    public JsonResult deleteWarehouseProductProducer (Long warehouseProductProducerId){
        JsonResult jsonResult = new JsonResult<>();
        if (warehouseProductProducerId != null){
            WarehouseProductProducer warehouseProductProducer = this.getById(warehouseProductProducerId);
            warehouseProductProducer.setIsDeleted(true);
            baseMapper.updateById(warehouseProductProducer);
            return jsonResult.success("删除成功");
        }else {
            return jsonResult.fail("删除失败");
        }
    }
}
